package beike;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        /*TreeSet<Character> set = new TreeSet<>(new Comparator<Character>() {
            @Override
            public int compare(Character o1, Character o2) {
                return o1 - o2;
            }
        });
        set.add('c');
        set.add('a');
        System.out.println(set.pollFirst());
        System.out.println(set.pollFirst());*/
        System.out.println(NS_String("caabeefa", 2));
    }
    public static String NS_String (String s, int k) {
        // write code here
        TreeSet<Character> set = new TreeSet<>(new Comparator<Character>() {
            @Override
            public int compare(Character o1, Character o2) {
                return o1 - o2;
            }
        });
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++){
            set.add(chars[i]);
        }
        Set<Character> set2 = new HashSet<>();
        for (int i = 1; i <= k; i++){
            set2.add(set.pollFirst());
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++){
            if (!set2.contains(s.charAt(i))){
                sb.append(s.charAt(i));
            }
        }
        return sb.toString();

    }
}
